/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
function LoginCtrl($scope, GenericResource) {
    $scope.credential = {};
    $scope.login = function() {
        var successCallback = function() {
            $scope.displayError = false;           
            window.location.href="index.html";
        };
        var errorCallback = function(result) {
            $scope.displayError = true;
            $scope.errors=result.data[0];            
            $scope.errorKeys=Object.keys($scope.errors);            
        };
        //acountInfo
        GenericResource.save({"path": "acountInfo","method":"login"}, $scope.credential, successCallback, errorCallback);       
    };
    $scope.notBlackListed = function(value) {
        var blacklist = ['bad@domain.com', 'verybad@domain.com'];
        return blacklist.indexOf(value) === -1;
    };
}

var loginApp = angular.module('app', ['ngResource','mgcrea.ngStrap.tooltip', 'mgcrea.ngStrap.datepicker']);
/*angular.module('app').value('$strapConfig', {
    datepicker: {
        language: 'zh-CN',
        format: 'yyyy-mm-dd',
        endDate: '2013-09-22'
    }
});*/
loginApp
.config(function($datepickerProvider) {
  angular.extend($datepickerProvider.defaults, {
    dateFormat: 'yyyy-MM-dd',
    maxDate:'2014-02-15',
    startWeek: 1
  });
});
loginApp.factory('GenericResource', function($resource) {
    var resource = $resource('rest/:path/:modelType/:method', {modelType: '@modelType', path: "items",method:null},
    {
        'queryAll': {method: 'GET', isArray: true},
        'query': {method: 'GET', isArray: false},
        'update': {method: 'PUT'},
        'save': {method: 'PUT'},
        'post': {method: 'POST'},
        'remove': {method: 'DELETE'},
        'delete': {method: 'DELETE'}});
    return resource;
});
loginApp.controller('LoginCtrl',function($scope, GenericResource) {
	LoginCtrl($scope, GenericResource);
});
